import * as turf from '@turf/turf'

class TrackUtils {
    constructor(cesium) {
        this._cesium = cesium;
    }

    /**
     * 
     * @param {Object} start 
     * @param {Object} end
     * {
     *  lon: Number,
     *  lat: Number,
     *  height: Number,
     *  time: Number
     * } 
     * @param {Object} config
     * {
     *  
     * }
     */
    static interpolate(start, end, config) {
        let sample = new this._cesium.SampledPositionProperty();
        
        let newPosition = [
            {
                x: start.lon,
                y: start.lat,
                z: start.height
            },
            {
                x: end.lon,
                y: end.lat,
                z: end.height
            }
        ];

        let allLength = getPositionLength(newPosition);
        let eachStep = 0.05;
        this._cesium.Math.setRandomNumberSeed(3);

        for(let i=0; i < newPosition.length; i++){
            let first = Array.from(newPosition);
            let moveArray = first.slice(0, i+1);
            let moveLength = TrackUtils.getPositionLength(moveArray);
           // let time = 
        }

    }

    static getPositionLength(data) {
        if(data && data.length > 0){
            let newPosition = data.map(p => {
                return [p.x, p.y]
            });
    
            let line = turf.lineString(newPosition);
            let options = {units: 'kilometers'};
            let kiloLength = turf.length(line, options);
            return parseFloat(kiloLength * 1000);
        }else{
            return 0;
        }
    
    }

}

export default TrackUtils;